//
//  SISSTakeLookRecordCell.m
//  SISSAPP
//
//  Created by 优房网 on 2017/7/14.
//  Copyright © 2017年 优房网. All rights reserved.
//

#import "SISSTakeLookRecordCell.h"
#import "SISSTakeLookModel.h"

@interface SISSTakeLookRecordCell ()

/// 称呼Label
@property (weak, nonatomic) UILabel *nameLabel;
/// 房屋信息Label
@property (weak, nonatomic) UILabel *infoLabel;
/// 看房时间Label
@property (weak, nonatomic) UILabel *timeTitleLabel;
/// 时间Label
@property (weak, nonatomic) UILabel *timeLabel;
/// 看房记录标签Label
@property (weak, nonatomic) UILabel *tagLabel;
/// 底部线条
@property (weak, nonatomic) UIView *lineView;

@end
@implementation SISSTakeLookRecordCell


- (void)setTakeLookModel:(SISSTakeLookModel *)takeLookModel {
    _takeLookModel = takeLookModel;
    
    // 根据身份证判断显示 先生、女士
    NSString *fisrtName = [takeLookModel.buyerName substringToIndex:1];
    NSInteger idNum = [[takeLookModel.idNumber substringWithRange:NSMakeRange(takeLookModel.idNumber.length - 2, 1)] integerValue];
    
    NSString *genderStr = (idNum % 2) == 0 ? @"女士" : @"先生";
    self.nameLabel.text = [NSString stringWithFormat:@"%@%@  %@",fisrtName,genderStr,@"求购"];
    self.infoLabel.text = [NSString stringWithFormat:@"%@-%@万 | %@-%@ | %@",@(takeLookModel.minPrice),@(takeLookModel.maxPrice),takeLookModel.region,takeLookModel.regionDetail,takeLookModel.houseType];
    self.timeLabel.text = [takeLookModel.takeLookDate substringToIndex:10];
    
    NSString *tagStr;
    UIColor *tagColor;
        switch (takeLookModel.brokerState) {
            case 0:
                tagStr = @"待确认";
                tagColor = COLOR(0x334A60);
                break;
    
            case 1:
                tagStr = @"已确认";
                tagColor = COLOR(0xFF1F1D);
                break;
    
            case 2:
                tagStr = @"已否认";
                tagColor = COLOR(0xAEC1D9);
                break;
    
            default:
                break;
        }
    
    self.tagLabel.textColor = tagColor;
    self.tagLabel.text = tagStr;
}

#pragma mark - UI
- (void)initUI {
    [super initUI];
    
    UILabel *nameLabel = [[UILabel alloc] init];
    nameLabel.textColor = MAIN_TEXT_COLOR;
    nameLabel.font = [UIFont systemFontOfSize:13];
    nameLabel.text = @"张先生 求购";
    [self.contentView addSubview:nameLabel];
    self.nameLabel = nameLabel;
    
    UILabel *infoLabel = [[UILabel alloc] init];
    infoLabel.textColor = MAIN_TEXT_COLOR;
    infoLabel.font = [UIFont systemFontOfSize:13];
    infoLabel.text = @"小区 | 售价 | 区域 | 面积 | 户型";
    [self.contentView addSubview:infoLabel];
    self.infoLabel = infoLabel;
    
    UILabel *timeTitleLabel = [[UILabel alloc] init];
    timeTitleLabel.textColor = MAIN_TEXT_COLOR;
    timeTitleLabel.font = [UIFont systemFontOfSize:13];
    timeTitleLabel.text = @"看房时间：";
    [self.contentView addSubview:timeTitleLabel];
    self.timeTitleLabel = timeTitleLabel;
    
    UILabel *timeLabel = [[UILabel alloc] init];
    timeLabel.textColor = MAIN_TEXT_COLOR;
    timeLabel.font = [UIFont systemFontOfSize:13];
    timeLabel.text = @"时间";
    [self.contentView addSubview:timeLabel];
    self.timeLabel = timeLabel;
    
    UILabel *tagLabel = [[UILabel alloc] init];
    tagLabel.textColor = MAIN_TEXT_COLOR;
    tagLabel.font = [UIFont systemFontOfSize:13];
    tagLabel.text = @"看房记录标签";
    [self.contentView addSubview:tagLabel];
    self.tagLabel = tagLabel;
    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.contentView addSubview:lineView];
    self.lineView = lineView;
}


#pragma mark - 约束
- (void)initConstraint {
    [super initConstraint];
    
    CGFloat margin = 8.0;
    WeakSelf
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(weakSelf.contentView).offset(2 * margin);
    }];
    
    [self.infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.nameLabel);
        make.top.equalTo(weakSelf.nameLabel.mas_bottom).offset(2 * margin);
    }];
    
    [self.timeTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.infoLabel);
        make.top.equalTo(weakSelf.infoLabel.mas_bottom).offset(2 * margin);
        make.bottom.equalTo(weakSelf.lineView).offset(-2 * margin);
    }];
    
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf.timeTitleLabel.mas_right);
        make.centerY.equalTo(weakSelf.timeTitleLabel);
    }];
    
    [self.tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.contentView);
        make.right.equalTo(weakSelf.contentView).offset(-2 * margin);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(weakSelf.contentView);
        make.height.mas_equalTo(1);
    }];
}


@end
